/*************************************************************************
Purpose:  This program creates a synthetic input file.  The time values,
          lats, and lons of the original input file are retained, but the
          accelerations are replaced with values obtained by upward continuing
          output files that have been precomputed.  These can either be
          simulated or based on models such as FES 2004.
**************************************************************************
Input:    None, but does open a real input file to get times, lats, x, y, z.
          Also opens output files for options, amplitudes, grid, etc.
**************************************************************************
Output:   None, but does create a synthetic input file.
**************************************************************************
Copyright 2010 Bryan Killett

This file is part of GAIA.

GAIA is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

GAIA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GAIA. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/
//Header file "definitions.hpp" declares many functions, constants, datatypes.
//In order to use the functions declared in definitions.hpp, must link
//with object code that includes functions.cpp.
#include "definitions.hpp"

int main(){

  input_s input;
  input_options_s current_input_options;
  long long i,j;
  string basefolder(gaiafolder());
  string file;
  string sim_file;
  string input_file(gaiafolder());//Filename of options file created in IDL.
  string input_folder(gaiafolder());//Folder where options/gaia files are found.
  ancillary_s ancillary;
  grid_s region;
  grid_s grid,regional_grid;
  model_s model;
  results_s results, regional_results;
  plot_options_s plot_options, temp_options,current_plot_options;//Temp used for region code, current used for sim_accels specific reasons.
  insitu_s insitu;//For tide gauge data, etc.
  //These variables are used to display run time of program after execution.
  time_t start_time,end_time;
  timespan_conversion_s timespan_conversion;
  string base;//This string forms the base part of the output filename.
  char s[max_length];//Need this because I'm not good at C++ strings.
  
  //The next variables are used to load data from cache or save to cache.
  string foldername, current_foldername,true_foldername,filename,newfile;

  //The following are used for fork() to enable parallel processing.
  pid_t pid;
  int rv;

  start_time = time(NULL);//Record time at start of program.
  
  //////////////////////////////////////////////////////////////////////////
  //Over-ride options are listed after the sim_output_choice switch-case!!
  //////////////////////////////////////////////////////////////////////////  

  //Controls which output to upward continue to create synthetic input file.

  //SYNTHETIC
  //1  - gaia type 10001.  Sin and cos coefficients loaded.NOT FINISHED!
  //2  - Same as 1, but amp and phase loaded.
  //3  - gaia type 10003.  Sin and cos coefficients loaded.NOT FINISHED!
  //4  - Same as 3, but amp and phase loaded.
  //5  - gaia type 10005.  Sin and cos coefficients loaded.NOT FINISHED!
  //6  - Same as 5, but amp and phase loaded.
  //7  - gaia type 10007.  Sin and cos coefficients loaded.NOT FINISHED!
  //8  - Same as 7, but amp and phase loaded.
  //9  - gaia type 10009.  Sin and cos coefficients loaded.NOT FINISHED!
  //10 - Same as 9, but amp and phase loaded.
  //11 - gaia type 10011.  Sin and cos coefficients loaded.NOT FINISHED!
  //12 - Same as 11, but amp and phase loaded.
  //13 - gaia type 10013.
  //14 - gaia type 10014.
  //15 - gaia type 10015.  Sin and cos coefficients, 230km type 10 grid.
  //16 - Same as 15, but amp and phase loaded.
  //17 - gaia type 10017.
  //18 - gaia type 10018.
  //19 - gaia type 10019.
  //20 - gaia type 10020, 500km grid.
  //21 - gaia type 10020, 100km grid. (Oh no, breaking sync!  C'est la vie...)
  //22 - gaia type 10020, 1050km grid.
  //23 - gaia type 10021, 200km grid - sorta-autosized
  //24 - gaia type 10021, 300km grid - autosized
  //25 - gaia type 10022, Type_10022_230km_gr_autosized
  //26 - gaia type 10023, Type_10023_230km_gr_autosized
  //27 - gaia type 10024, Type_10024_230km_gr_autosized
  //28 - gaia type 10025, Type_10025_230km_gr_autosized
  //29 - gaia type 10026, Type_10026_230km_gr_autosized
  //30 - gaia type 10027, Type_10027_230km_gr_autosized
  //31 - gaia type 10028, Type_10028_230km_gr_autosized
  //32 - gaia type 10029, Type_10029_230km_gr_autosized
  //33 - gaia type 10030, Type_10030_230km_gr_autosized
  //34 - gaia type 10031, Type_10031_230km_gr_autosized
  //35 - gaia type 10032, Type_10032_230km_gr_autosized
  //36 - gaia type 10033, Type_10033_230km_gr_autosized
  //37 - gaia type 10034, Type_10034_230km_gr_autosized
  //38 - gaia type 10035, Type_10035_230km_gr_autosized
  //39 - gaia type 10036, Type_10036_230km_gr_autosized
  //40 - gaia type 10037, Type_10037_230km_gr_autosized
  //41 - gaia type 10038, Type_10038_230km_gr_autosized
  //42 - gaia type 10039, Type_10039_230km_gr_autosized
  //43 - gaia type 10040, Type_10040_230km_gr_autosized  
  //44 - gaia type 10041, Type_10041_230km_gr_autosized
  //45 - gaia type 10042, Type_10042_230km_gr_autosized
  //46 - gaia type 10043, Type_10043_230km_gr_autosized
  //47 - gaia type 10044, Type_10044_230km_gr_autosized
  //48 - gaia type 10045, Type_10045_230km_gr_autosized (1 OF 10 PTS!)
  //49 - gaia type 10046, Type_10046_230km_gr_autosized
  //50 - gaia type 10047, Type_10047_230km_gr_autosized
  //51 - gaia type 10048, Type_10048_230km_gr_autosized
  //52 - gaia type 10049, Type_10049_230km_gr_autosized
  //53-54 weren't finished.
  //55 - real data, Real data without np anomaly, support 3, gr 230km, ovlp 2850km, const,linear,m2,o1,annual
  //56 - Real data with k1 but without np anomaly, support 3, gr 230km, ovlp 2850km, const,linear,m2,o1,k1,annual
  //57 - Real data, hmc 202, support 3, type 128, 600k verif, 300 gr, 10 periods
  //58 - gaia type 10022, Type_10022_600km_gr_autosized
  //59 - gaia type 10022, Type_10022_230km_gr_type_10
  //60 - FES tides: M2,K1,O1,P1,S2,N2,K2,Q1,Mf,Mm
  //61 - edited version of gaia type 10015.  Sin and cos coefficients, 230km type 10 grid.
  //62 - gaia type 10050, Type_10050_230km_gr_type_10
  //63 - gaia type 10051, Type_10051_230km_gr_type_10
  //64 - gaia type 10052, Type_10052_230km_gr_type_10
  //65 - gaia type 10053, Type_10053_230km_gr_type_10
  //66 - gaia type 10048, Type_10048_custom_grid_NP_spacing_230km
  //67 - NOLAND, 230KM GR MasconFES M2, deg 90 - deg 150, Type_1003_MasconFES_deg90_minus_deg150
  //68 - gaia type 10044, Type_10044_230km_gr_type_10
  //69 - NOLAND, 230KM GR MasconFES M2, deg 90 - infinity, Type_1003_MasconFES_deg90_minus_infinity
  //70 - NOLAND, 230KM GR MasconFES K1, deg 90 - deg 150, Type_1003_MasconFES_K1_deg90_minus_deg150
  //71 - NOLAND, 230KM GR MasconFES K1, deg 90 - infinity, Type_1003_MasconFES_K1_deg90_minus_infinity
  //72 - NOLAND, 230KM GR MasconFES M2,K1, deg 90 - infinity, Type_1003_MasconFES_M2_K1_deg90_minus_infinity
  //73 - gaia type 10015.  Sin and cos coefficients, 230km type 10 grid, fixed?
  //74 - gaia type 10054, Type_10054_230km_gr_type_10
  //75 - gaia type 10055, Type_10055_230km_gr_type_10
  //76 - produced manually using custom grid,Custom_NP_M2_10cm_sine_0cm_cosine
  //77 - NOLAND, 230KM GR MasconFES M2, deg 200 - infinity, Type_1003_MasconFES_M2_deg200_minus_infinity
  //78 - MasconFES M2, 230km gr, deg 90 - infinity, MasconFES_230km_deg90_minus_infinity_including_land
  //79 - MasconFES M2, 100km gr, deg 90 - infinity, MasconFES_100km_deg90_minus_infinity_including_land
  //80 - MasconFES M2, 230km gr, deg 200- infinity, MasconFES_230km_deg200_minus_infinity_including_land
  //81 - MasconFES M2, 100km gr, deg 200- infinity, MasconFES_100km_deg200_minus_infinity_including_land
  //82 - MasconFES M2, 230km gr, deg 300- infinity, MasconFES_230km_deg300_minus_infinity_including_land
  //83 - MasconFES M2, 100km gr, deg 300- infinity, MasconFES_100km_deg300_minus_infinity_including_land
  //84 - MasconFES K1, 230km gr, deg 90 - infinity, MasconFES_K1_230km_deg90_minus_infinity_including_land
  //85 - MasconFES K1, 100km gr, deg 90 - infinity, MasconFES_K1_100km_deg90_minus_infinity_including_land
  //86 - MasconFES M2,  50km gr, deg 90 - infinity, MasconFES_M2_50km_deg90_minus_infinity_including_land
  //87 - Hudson NS 300km mascond using type 10 300km
  //88 - Hudson NS 300km mascond using type 10 230km
  //89 - Hudson NS 300km mascond using type 10 100km
  //90 - Hudson NS 300km mascond using type 10 50km
  //91 - Hudson box 130km mascond using type 10 230km
  //92 - Hudson box 130km mascond using type 10 150km
  //93 - Hudson box 130km mascond using type 10 100km
  //94 - Hudson box 130km mascond using type 10  50km
  //95 - Hudson NS 130km mascond using type 10 230km
  //96 - Hudson NS 130km mascond using type 10 150km
  //97 - Hudson NS 130km mascond using type 10 100km
  //98 - Hudson NS 130km mascond using type 10  50km
  //99 - Hudson NS 130km diff inf and deg90 mascond using 230km on godric
  //100- Hudson NS 130km diff inf and deg90 mascond using 150km on godric
  //101- Hudson NS 130km diff inf and deg90 mascond using 100km on godric
  //102- Hudson NS 130km diff inf and deg90 mascond using  50km on godric
  //103- Hudson NS 130km deg90 mascond using 230km on godric
  //104- Hudson NS 130km deg90 mascond using 150km on godric
  //105- Hudson NS 130km deg90 mascond using 100km on godric
  //106- Hudson NS 130km deg90 mascond using  50km on godric
  //107- Hudson N  130km diff inf and deg90 mascond using 230km on godric  
  //108- Hudson N  130km diff inf and deg90 mascond using 150km on godric  
  //109- Hudson N  130km diff inf and deg90 mascond using 100km on godric  
  //110- Hudson N  130km diff inf and deg90 mascond using  50km on godric  
  //111- Hudson S  130km diff inf and deg90 mascond using 230km on godric  
  //112- Hudson S  130km diff inf and deg90 mascond using 150km on godric  
  //113- Hudson S  130km diff inf and deg90 mascond using 100km on godric  
  //114- Hudson S  130km diff inf and deg90 mascond using  50km on godric  
  //115- Hudson NS 130km diff inf and deg90 nonlinearity in 230km mascond maps
  //116- Hudson NS 130km diff inf and deg90 nonlinearity in 50km mascond maps
  //117- Hudson NS 130km 500cm diff inf and deg90 mascond using 300km, double precision
  //118- Hudson NS 130km 500cm diff inf and deg90 mascond using 230km, double precision
  //119- Hudson NS 130km 500cm diff inf and deg90 mascond using  50km, double precision
  //120- Hudson N  130km 500cm diff inf and deg90 mascond using 300km, double precision
  //121- Hudson N  130km 500cm diff inf and deg90 mascond using 230km, double precision
  //122- Hudson N  130km 500cm diff inf and deg90 mascond using  50km, double precision
  //123- Hudson S  130km 500cm diff inf and deg90 mascond using 300km, double precision
  //124- Hudson S  130km 500cm diff inf and deg90 mascond using 230km, double precision
  //125- Hudson S  130km 500cm diff inf and deg90 mascond using  50km, double precision
  //126- Hudson NS 130km 500cm diff inf and deg90 nonlinearity mascond using 50km, double precision
  //127- Hudson N  130km 500cm diff inf and deg90 mascond using 20km, double precision, O2 switch on laptop
  //128- MasconFES M2, 350km gr, deg 90 - infinity, new FES area weighting and mascon area code.
  //129- MasconFES M2, 230km gr, deg 90 - infinity, new FES area weighting and mascon area code.
  //130- MasconFES M2, 150km gr, deg 90 - infinity, new FES area weighting and mascon area code.
  //131- MasconFES M2, 100km gr, deg 90 - infinity, new FES area weighting and mascon area code.
  //132- MasconFES M2,  50km gr, deg 90 - infinity, new FES area weighting and mascon area code.
  //133- MasconFES M2, 350km gr, deg 90 - infinity, new FES area weighting but old mascon area code.
  //134- MasconFES M2, 50km gr, deg 90 - infinity, new FES area weighting but old mascon area code.
  //135- Old area and old FES weighting code, negpos sums, Hudson N 130km 500cm diff inf and deg 90 mascond using 350km grid
  //136- Old area and old FES weighting code, negpos sums, Hudson N 130km 500cm diff inf and deg 90 mascond using 50km grid
  //137- New area and new FES weighting code, negpos sums, Hudson N 130km 500cm diff inf and deg 90 mascond using 350km grid
  //138- New area and new FES weighting code, negpos sums, Hudson N 130km 500cm diff inf and deg 90 mascond using 50km grid
  //139- Hudson N 130km 500cm diff inf and deg 90 mascond using 350km grid, old area and weighting minus new
  //140- Hudson N 130km 500cm diff inf and deg 90 mascond using 50km grid, old area and weighting minus new
  //141- Hudson N 130km 500cm mascond using 350km grid
  //142- Hudson N 130km 500cm mascond using 50km grid
  //143- Hudson N 130km 500cm diff inf deg20 mascond using 350km grid
  //144- Hudson N 130km 500cm diff inf deg20 mascond using 50km grid
  //145- Hudson N 130km 500cm diff inf deg40 mascond using 350km grid
  //146- Hudson N 130km 500cm diff inf deg40 mascond using 50km grid
  //147- Hudson N 130km 500cm diff inf deg60 mascond using 350km grid
  //148- Hudson N 130km 500cm diff inf deg60 mascond using 50km grid
  //149- BROKENHudson N 130km 500cm diff inf deg50 mascond using 350km grid
  //150- BROKENHudson N 130km 500cm diff inf deg50 mascond using 50km grid
  //151- BROKENHudson N 130km 500cm diff inf deg75 mascond using 350km grid
  //152- BROKENHudson N 130km 500cm diff inf deg75 mascond using 50km grid
  //153- Hudson N 130km 500cm diff inf deg90 mascond using 350km grid
  //154- Hudson N 130km 500cm diff inf deg90 mascond using 50km grid
  //155- Hudson N 130km 500cm diff inf deg55 mascond using 350km grid
  //156- Hudson N 130km 500cm diff inf deg55 mascond using 50km grid
  //157- Hudson N 130km 500cm diff inf deg65 mascond using 350km grid
  //158- Hudson N 130km 500cm diff inf deg65 mascond using 50km grid
  //159- Hudson N 130km 500cm diff inf deg70 mascond using 350km grid
  //160- Hudson N 130km 500cm diff inf deg70 mascond using 50km grid
  //161- Hudson N 130km 500cm diff inf deg80 mascond using 350km grid
  //162- Hudson N 130km 500cm diff inf deg80 mascond using 50km grid
  //163- Hudson N 130km 500cm diff inf deg85 mascond using 350km grid
  //164- Hudson N 130km 500cm diff inf deg85 mascond using 50km grid
  //165- Hudson N 130km 500cm diff inf deg25 mascond using 350km grid
  //166- Hudson N 130km 500cm diff inf deg25 mascond using 50km grid
  //167- Hudson N 130km 500cm diff inf deg30 mascond using 350km grid
  //168- Hudson N 130km 500cm diff inf deg30 mascond using 50km grid
  //169- Hudson N 130km 500cm diff inf deg49 mascond using 350km grid
  //170- Hudson N 130km 500cm diff inf deg49 mascond using 50km grid
  //171- Hudson N 130km 500cm diff inf deg51 mascond using 350km grid
  //172- Hudson N 130km 500cm diff inf deg51 mascond using 50km grid
  //173- Hudson N 130km 500cm diff inf deg74 mascond using 350km grid
  //174- Hudson N 130km 500cm diff inf deg74 mascond using 50km grid
  //175- Hudson N 130km 500cm diff inf deg76 mascond using 350km grid
  //176- Hudson N 130km 500cm diff inf deg76 mascond using 50km grid
  //177- Hudson N 130km 500cm diff inf deg50take2 mascond using 350km grid
  //178- Hudson N 130km 500cm diff inf deg50take2 mascond using 50km grid
  //179- Hudson N 130km 500cm diff inf deg75take2 mascond using 350km grid
  //180- Hudson N 130km 500cm diff inf deg75take2 mascond using 50km grid
  //181- Hudson N 130km 500cm diff inf deg10 mascond using 350km grid
  //182- Hudson N 130km 500cm diff inf deg10 mascond using 50km grid
  //183- Hudson N 130km 500cm diff inf deg27 mascond using 350km grid
  //184- Hudson N 130km 500cm diff inf deg27 mascond using 50km grid
  //185- Hudson N 130km 500cm diff inf deg32 mascond using 350km grid
  //186- Hudson N 130km 500cm diff inf deg32 mascond using 50km grid
  //187- Hudson N 130km 500cm diff inf deg35 mascond using 350km grid
  //188- Hudson N 130km 500cm diff inf deg35 mascond using 50km grid
  //189- Hudson N 130km 500cm diff inf deg37 mascond using 350km grid
  //190- Hudson N 130km 500cm diff inf deg37 mascond using 50km grid
  //191- Hudson N 130km 500cm diff inf deg110 mascond using 350km grid
  //192- Hudson N 130km 500cm diff inf deg110 mascond using 50km grid
  //193- Hudson N 130km 500cm diff inf deg130 mascond using 350km grid
  //194- Hudson N 130km 500cm diff inf deg130 mascond using 50km grid
  //195- FES M2,K1, diff inf and deg90, 350km, new areas
  //196- FES M2,K1, diff inf and deg90, 230km, new areas
  //197- FES M2,K1, diff inf and deg90, 150km, new areas
  //198- FES M2,K1, diff inf and deg90, 100km, new areas
  //199- FES M2,K1, diff inf and deg90, 50km, new areas
  //200- gaia type 10056, Type_10056_230km_gr_type_10
  //201- gaia type 10048, Type 10048, 100km type 10 gr
  //202- gaia type 10048, Type 10048, 1050km type 10 gr
  int sim_output_choice = 202;

  sprintf(s,"input_and_orbit_sim_type_%d_supp0.txt",sim_output_choice);
  current_input_options.output_filename = s;
  string ifolder;
  switch(sim_output_choice){
    default: cout<<"WARNING!!! Choice "<<sim_output_choice<<" isn't recognized."<<endl;
    case 2:{//produced by analysis_options.type == 10002 on 2008-05-20
      ifolder="output/simulations/Type_10002_gr_200km/";
      break;
    }
    case 4:{//produced by analysis_options.type == 10004 on 2008-
      ifolder="output/simulations/Type_10004_gr_200km/";
      break;
    }
    case 6:{//produced by analysis_options.type == 10006 on 2008-08-22
      ifolder="output/simulations/Type_10006_gr_200km/";
      break;
    }
    case 8:{//produced by analysis_options.type == 10008 on 2008-05-30
      ifolder="output/simulations/Type_10008_gr_200km/";
      break;
    }
    case 10:{//produced by analysis_options.type == 10010 on 2008-06-10
      ifolder="output/simulations/Type_10010_gr_200km/";
      break;
    }
    case 12:{//produced by analysis_options.type == 10012 on 2008-08-20
      ifolder="output/simulations/Type_10012_gr_weird_np_separated/";
      break;
    }
    case 13:{//produced by analysis_options.type == 10013 on 2008-07-30
      ifolder="output/simulations/Type_10013_gr_200km/";
      break;
    }
    case 14:{//produced by analysis_options.type == 10014 on 2008-08-22
      ifolder="output/simulations/Type_10014_gr_weird_np_separated/";
      break;
    }
    case 15:{//WARNING, USES AMP/PHASE NUMBERS, SO SINE COEF IS 60CM!! produced by analysis_options.type == 10015 on 2010-03-01
      ifolder="output/simulations/Type_10015_230km_gr_type_10/";
      break;
    }
    case 16:{//produced by manually copying 10010 on 2008-07-31
      ifolder="output/simulations/Type_10016_gr_200km/";
      break;
    }
    case 17:{//produced by analysis_options.type == 10017 on 2008-08-22
      ifolder="output/simulations/Type_10017_gr_200km/";
      break;
    }
    case 18:{//produced by analysis_options.type == 10018 on 2008-08-28
      ifolder="output/simulations/Type_10018_gr_200km/";
      break;
    }
    case 19:{//produced by analysis_options.type == 10019 on 2008-08-28
      ifolder="output/simulations/Type_10019_gr_200km/";
      break;
    }
    case 20:{//produced by analysis_options.type == 10020 on 2008-09-13
      ifolder="output/simulations/Type_10020_gr_500km/";
      break;
    }
    case 21:{//produced by analysis_options.type == 10020 on 2008-09-17
      ifolder="output/simulations/Type_10020_gr_100km/";
      break;
    }
    case 22:{//produced by analysis_options.type == 10020 on 2008-09-21
      ifolder="output/simulations/Type_10020_gr_1050km/";
      break;
    }
    case 23:{//produced by analysis_options.type == 10021 on 2008-09-28
      ifolder="output/simulations/Type_10021_gr_200km_sorta_autosized/";
      break;
    }
    case 24:{//produced by analysis_options.type == 10021 on 2008-09-28
      ifolder="output/simulations/Type_10021_gr_300km_autosized/";
      break;
    }
    case 25:{//produced by analysis_options.type == 10022 on 2008-11-08
      ifolder="output/simulations/Type_10022_230km_gr_autosized/";
      break;
    }
    case 26:{//produced by analysis_options.type == 10023 on 2008-12-17
      ifolder="output/simulations/Type_10023_230km_gr_autosized/";
      break;
    }
    case 27:{//produced by analysis_options.type == 10024 on 2008-12-17
      ifolder="output/simulations/Type_10024_230km_gr_autosized/";
      break;
    }
    case 28:{//produced by analysis_options.type == 10025 on 2009-02-03
      ifolder="output/simulations/Type_10025_230km_gr_autosized/";
      break;
    }
    case 29:{//produced by analysis_options.type == 10026 on 2009-02-05
      ifolder="output/simulations/Type_10026_230km_gr_autosized/";
      break;
    }
    case 30:{//produced by analysis_options.type == 10027 on 2009-02-07
      ifolder="output/simulations/Type_10027_230km_gr_autosized/";
      break;
    }
    case 31:{//produced by analysis_options.type == 10028 on 2009-02-09
      ifolder="output/simulations/Type_10028_230km_gr_autosized/";
      break;
    }
    case 32:{//produced by analysis_options.type == 10029 on 2009-02-09
      ifolder="output/simulations/Type_10029_230km_gr_autosized/";
      break;
    }
    case 33:{//produced by analysis_options.type == 10030 on 2009-02-13
      ifolder="output/simulations/Type_10030_230km_gr_autosized/";
      break;
    }
    case 34:{//produced by analysis_options.type == 10031 on 2009-02-13
      ifolder="output/simulations/Type_10031_230km_gr_autosized/";
      break;
    }
    case 35:{//produced by analysis_options.type == 10032 on 2009-02-16
      ifolder="output/simulations/Type_10032_230km_gr_autosized/";
      break;
    }
    case 36:{//produced by analysis_options.type == 10033 on 2009-02-16
      ifolder="output/simulations/Type_10033_230km_gr_autosized/";
      break;
    }
    case 37:{//produced by analysis_options.type == 10034 on 2009-02-16
      ifolder="output/simulations/Type_10034_230km_gr_autosized/";
      break;
    }
    case 38:{//produced by analysis_options.type == 10035 on 2009-02-16
      ifolder="output/simulations/Type_10035_230km_gr_autosized/";
      break;
    }
    case 39:{//produced by analysis_options.type == 10036 on 2009-02-23
      ifolder="output/simulations/Type_10036_230km_gr_autosized/";
      break;
    }
    case 40:{//produced by analysis_options.type == 10037 on 2009-02-23
      ifolder="output/simulations/Type_10037_230km_gr_autosized/";
      break;
    }
    case 41:{//produced by analysis_options.type == 10038 on 2009-03-04
      ifolder="output/simulations/Type_10038_230km_gr_autosized/";
      break;
    }
    case 42:{//produced by analysis_options.type == 10039 on 2009-03-22
      ifolder="output/simulations/Type_10039_230km_gr_autosized/";
      break;
    }
    case 43:{//produced by analysis_options.type == 10040 on 2009-03-23
      ifolder="output/simulations/Type_10040_230km_gr_autosized/";
      break;
    }
    case 44:{//produced by analysis_options.type == 10041 on 2009-03-24
      ifolder="output/simulations/Type_10041_230km_gr_autosized/";
      break;
    }
    case 45:{//produced by analysis_options.type == 10042 on 2009-03-24
      ifolder="output/simulations/Type_10042_230km_gr_autosized/";
      break;
    }
    case 46:{//produced by analysis_options.type == 10043 on 2009-03-24
      ifolder="output/simulations/Type_10043_230km_gr_autosized/";
      break;
    }
    case 47:{//produced by analysis_options.type == 10044 on 2009-03-24
      ifolder="output/simulations/Type_10044_230km_gr_autosized/";
      break;
    }
    case 48:{//produced by analysis_options.type == 10045 on 2009-03-27
      ifolder="output/simulations/Type_10045_230km_gr_autosized/";
      break;
    }
    case 49:{//produced by analysis_options.type == 10046 on 2009-03-28
      ifolder="output/simulations/Type_10046_230km_gr_autosized/";
      break;
    }
    case 50:{//produced by analysis_options.type == 10047 on 2009-03-28
      ifolder="output/simulations/Type_10047_230km_gr_autosized/";
      break;
    }
    case 51:{//produced by analysis_options.type == 10048 on 2009-04-01
      ifolder="output/simulations/Type_10048_230km_gr_autosized/";
      break;
    }
    case 52:{//produced by analysis_options.type == 10049 on 2009-04-01
      ifolder="output/simulations/Type_10049_230km_gr_autosized/";
      break;
    }
    case 55:{//produced by modifying real data on 2009-04-11
      ifolder="output/simulations/Real data without np anomaly, support 3, gr 230km, ovlp 2850km, const,linear,m2,o1,annual/";
      break;
    }
    case 56:{//produced by modifying real data on 2009-04-12
      ifolder="output/simulations/Real data with k1 but without np anomaly, support 3, gr 230km, ovlp 2850km, const,linear,m2,o1,k1,annual/";
      break;
    }
    case 57:{//produced by loading real data on 2009-04-22
      ifolder="output/simulations/Real data, hmc 202, support 3, type 128, 600k verif, 300 gr, 10 periods/";
      break;
    }
    case 58:{//produced by analysis_options.type == 10022 on 2009-11-09
      ifolder="output/simulations/Type_10022_gr_600km_autosized/";
      break;
    }
    case 59:{//produced by analysis_options.type == 10022 on 2010-01-18
      ifolder="output/simulations/Type_10022_230km_gr_type_10/";
      break;
    }
    case 60:{//produced on 2010-02-12
      ifolder="output/simulations/FES_big10_230km_gr_type_10/";
      break;
    }
    case 61:{//produced by editing analysis_options.type == 10015 on 2010-03-04
      ifolder="output/simulations/Type_10015edited_230km_gr_type_10/";
      break;
    }
    case 62:{//produced by analysis_options.type == 10050 on 2010-03-11
      ifolder="output/simulations/Type_10050_230km_gr_type_10/";
      break;
    }
    case 63:{//produced by analysis_options.type == 10051 on 2010-03-11
      ifolder="output/simulations/Type_10051_230km_gr_type_10/";
      break;
    }
    case 64:{//produced by analysis_options.type == 10052 on 2010-03-19
      ifolder="output/simulations/Type_10052_230km_gr_type_10/";
      break;
    }
    case 65:{//produced by analysis_options.type == 10053 on 2010-03-19
      ifolder="output/simulations/Type_10053_230km_gr_type_10/";
      break;
    }
    case 66:{//produced by analysis_options.type == 10048 on 2010-03-27
      ifolder="output/simulations/Type_10048_custom_grid_NP_spacing_230km/";
      break;
    }
    case 67:{//produced by analysis_options.type == 1003 on 2010-05-29
      ifolder="output/simulations/Type_1003_MasconFES_deg90_minus_deg150/";
      break;
    }
    case 68:{//produced by analysis_options.type == 10044 on 2010-05-30
      ifolder="output/simulations/Type_10044_230km_gr_type_10/";
      break;
    }
    case 69:{//produced by analysis_options.type == 1003 on 2010-06-02
      ifolder="output/simulations/Type_1003_MasconFES_deg90_minus_infinity/";
      break;
    }
    case 70:{//produced by analysis_options.type == 1003 on 2010-06-03
      ifolder="output/simulations/Type_1003_MasconFES_K1_deg90_minus_deg150/";
      break;
    }
    case 71:{//produced by analysis_options.type == 1003 on 2010-06-03
      ifolder="output/simulations/Type_1003_MasconFES_K1_deg90_minus_infinity/";
      break;
    }
    case 72:{//produced by analysis_options.type == 1003 on 2010-06-03
      ifolder="output/simulations/Type_1003_MasconFES_M2_K1_deg90_minus_infinity/";
      break;
    }
    case 73:{//produced by analysis_options.type == 10015 on 2010-06-04
      ifolder="output/simulations/Type_10015_230km_gr_type_10_new/";
      break;
    }
    case 74:{//produced by analysis_options.type == 10054 on 2010-06-05
      ifolder="output/simulations/Type_10054_230km_gr_type_10/";
      break;
    }
    case 75:{//produced by analysis_options.type == 10055 on 2010-06-07
      ifolder="output/simulations/Type_10055_230km_gr_type_10/";
      break;
    }
    case 76:{//produced manually using custom grid on 2010-06-10
      ifolder="output/simulations/Custom_NP_M2_10cm_sine_0cm_cosine/";
      break;
    }
    case 77:{//produced by analysis_options.type == 1003 on 2010-06-30
      ifolder="output/simulations/Type_1003_MasconFES_M2_deg200_minus_infinity/";
      break;
    }
    case 78:{//produced by analysis_options.type == 1003 on 2010-07-06
      ifolder="output/simulations/MasconFES_230km_deg90_minus_infinity_including_land/";
      break;
    }
    case 79:{//produced by analysis_options.type == 1003 on 2010-07-06
      ifolder="output/simulations/MasconFES_100km_deg90_minus_infinity_including_land/";
      break;
    }
    case 80:{//produced by analysis_options.type == 1003 on 2010-07-06
      ifolder="output/simulations/MasconFES_230km_deg200_minus_infinity_including_land/";
      break;
    }
    case 81:{//produced by analysis_options.type == 1003 on 2010-07-06
      ifolder="output/simulations/MasconFES_100km_deg200_minus_infinity_including_land/";
      break;
    }
    case 82:{//produced by analysis_options.type == 1003 on 2010-07-06
      ifolder="output/simulations/MasconFES_230km_deg300_minus_infinity_including_land/";
      break;
    }
    case 83:{//produced by analysis_options.type == 1003 on 2010-07-06
      ifolder="output/simulations/MasconFES_100km_deg300_minus_infinity_including_land/";
      break;
    }
    case 84:{//produced by analysis_options.type == 1003 on 2010-07-06
      ifolder="output/simulations/MasconFES_K1_230km_deg90_minus_infinity_including_land/";
      break;
    }
    case 85:{//produced by analysis_options.type == 1003 on 2010-07-06
      ifolder="output/simulations/MasconFES_K1_100km_deg90_minus_infinity_including_land/";
      break;
    }
    case 86:{//produced by analysis_options.type == 1003 on 2010-07-08
      ifolder="output/simulations/MasconFES_M2_50km_deg90_minus_infinity_including_land/";
      break;
    }
    case 87:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson NS 300km mascond using type 10 300km/";
      break;
    }
    case 88:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson NS 300km mascond using type 10 230km/";
      break;
    }
    case 89:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson NS 300km mascond using type 10 100km/";
      break;
    }
    case 90:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson NS 300km mascond using type 10 50km/";
      break;
    }
    case 91:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson box 130km mascond using type 10 230km/";
      break;
    }
    case 92:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson box 130km mascond using type 10 150km/";
      break;
    }
    case 93:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson box 130km mascond using type 10 100km/";
      break;
    }
    case 94:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson box 130km mascond using type 10 50km/";
      break;
    }
    case 95:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson NS 130km mascond using type 10 230km/";
      break;
    }
    case 96:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson NS 130km mascond using type 10 150km/";
      break;
    }
    case 97:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson NS 130km mascond using type 10 100km/";
      break;
    }
    case 98:{//produced by analysis_options.type == 1003 on 2010-07-14
      ifolder="output/simulations/Hudson NS 130km mascond using type 10 50km/";
      break;
    }
    case 99:{//produced by analysis_options.type == 1003 on 2010-07-18
      ifolder="output/simulations/Hudson NS 130km diff inf and deg90 mascond using 230km on godric/";
      break;
    }
    case 100:{//produced by analysis_options.type == 1003 on 2010-07-18
      ifolder="output/simulations/Hudson NS 130km diff inf and deg90 mascond using 150km on godric/";
      break;
    }
    case 101:{//produced by analysis_options.type == 1003 on 2010-07-18
      ifolder="output/simulations/Hudson NS 130km diff inf and deg90 mascond using 100km on godric/";
      break;
    }
    case 102:{//produced by analysis_options.type == 1003 on 2010-07-18
      ifolder="output/simulations/Hudson NS 130km diff inf and deg90 mascond using 50km on godric/";
      break;
    }
    case 103:{//produced by analysis_options.type == 1003 on 2010-07-19
      ifolder="output/simulations/Hudson NS 130km deg90 mascond using 230km on godric/";
      break;
    }
    case 104:{//produced by analysis_options.type == 1003 on 2010-07-19
      ifolder="output/simulations/Hudson NS 130km deg90 mascond using 150km on godric/";
      break;
    }
    case 105:{//produced by analysis_options.type == 1003 on 2010-07-19
      ifolder="output/simulations/Hudson NS 130km deg90 mascond using 100km on godric/";
      break;
    }
    case 106:{//produced by analysis_options.type == 1003 on 2010-07-19
      ifolder="output/simulations/Hudson NS 130km deg90 mascond using 50km on godric/";
      break;
    }
    case 107:{//produced by analysis_options.type == 1003 on 2010-07-20
      ifolder="output/simulations/Hudson N 130km diff inf and deg90 mascond using 230km on godric/";
      break;
    }
    case 108:{//produced by analysis_options.type == 1003 on 2010-07-20
      ifolder="output/simulations/Hudson N 130km diff inf and deg90 mascond using 150km on godric/";
      break;
    }
    case 109:{//produced by analysis_options.type == 1003 on 2010-07-20
      ifolder="output/simulations/Hudson N 130km diff inf and deg90 mascond using 100km on godric/";
      break;
    }
    case 110:{//produced by analysis_options.type == 1003 on 2010-07-20
      ifolder="output/simulations/Hudson N 130km diff inf and deg90 mascond using 50km on godric/";
      break;
    }
    case 111:{//produced by analysis_options.type == 1003 on 2010-07-20
      ifolder="output/simulations/Hudson S 130km diff inf and deg90 mascond using 230km on godric/";
      break;
    }
    case 112:{//produced by analysis_options.type == 1003 on 2010-07-20
      ifolder="output/simulations/Hudson S 130km diff inf and deg90 mascond using 150km on godric/";
      break;
    }
    case 113:{//produced by analysis_options.type == 1003 on 2010-07-20
      ifolder="output/simulations/Hudson S 130km diff inf and deg90 mascond using 100km on godric/";
      break;
    }
    case 114:{//produced by analysis_options.type == 1003 on 2010-07-20
      ifolder="output/simulations/Hudson S 130km diff inf and deg90 mascond using 50km on godric/";
      break;
    }
    case 115:{//produced by analysis_options.type == 1003 on 2010-07-26
      ifolder="output/simulations/Hudson NS 130km diff inf and deg90 nonlinearity in 230km mascond maps/";
      break;
    }
    case 116:{//produced by analysis_options.type == 1003 on 2010-07-26
      ifolder="output/simulations/Hudson NS 130km diff inf and deg90 nonlinearity in 50km mascond maps/";
      break;
    }
    case 117:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson NS 130km 500cm diff inf and deg90 mascond using 300km, double precision/";
      break;
    }
    case 118:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson NS 130km 500cm diff inf and deg90 mascond using 230km, double precision/";
      break;
    }
    case 119:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson NS 130km 500cm diff inf and deg90 mascond using 50km, double precision/";
      break;
    }
    case 120:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson N 130km 500cm diff inf and deg90 mascond using 300km, double precision/";
      break;
    }
    case 121:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson N 130km 500cm diff inf and deg90 mascond using 230km, double precision/";
      break;
    }
    case 122:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson N 130km 500cm diff inf and deg90 mascond using 50km, double precision/";
      break;
    }
    case 123:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson S 130km 500cm diff inf and deg90 mascond using 300km, double precision/";
      break;
    }
    case 124:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson S 130km 500cm diff inf and deg90 mascond using 230km, double precision/";
      break;
    }
    case 125:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson S 130km 500cm diff inf and deg90 mascond using 50km, double precision/";
      break;
    }
    case 126:{//produced by analysis_options.type == 1003 on 2010-07-28
      ifolder="output/simulations/Hudson NS 130km 500cm diff inf and deg90 nonlinearity mascond using 50km, double precision/";
      break;
    }
    case 127:{//produced by analysis_options.type == 1003 on 2010-07-30
      ifolder="output/simulations/Hudson N 130km 500cm diff inf and deg90 mascond using 20km, double precision, O2 switch on laptop/";
      break;
    }
    case 128:{//produced by analysis_options.type == 1003 on 2010-09-01
      ifolder="output/simulations/MasconFES M2, 350km gr, deg 90 - infinity, new FES area weighting and mascon area code./";
      break;
    }
    case 129:{//produced by analysis_options.type == 1003 on 2010-09-01
      ifolder="output/simulations/MasconFES M2, 230km gr, deg 90 - infinity, new FES area weighting and mascon area code./";
      break;
    }
    case 130:{//produced by analysis_options.type == 1003 on 2010-09-01
      ifolder="output/simulations/MasconFES M2, 150km gr, deg 90 - infinity, new FES area weighting and mascon area code./";
      break;
    }
    case 131:{//produced by analysis_options.type == 1003 on 2010-09-01
      ifolder="output/simulations/MasconFES M2, 100km gr, deg 90 - infinity, new FES area weighting and mascon area code./";
      break;
    }
    case 132:{//produced by analysis_options.type == 1003 on 2010-09-01
      ifolder="output/simulations/MasconFES M2, 50km gr, deg 90 - infinity, new FES area weighting and mascon area code./";
      break;
    }
    case 133:{//produced by analysis_options.type == 1003 on 2010-09-02
      ifolder="output/simulations/MasconFES M2, 350km gr, deg 90 - infinity, new FES area weighting but old mascon area code./";
      break;
    }
    case 134:{//produced by analysis_options.type == 1003 on 2010-09-02
      ifolder="output/simulations/MasconFES M2, 50km gr, deg 90 - infinity, new FES area weighting but old mascon area code./";
      break;
    }
    case 135:{//produced by analysis_options.type == 1003 on 2010-09-07
      ifolder="output/simulations/Old area and old FES weighting code, negpos sums, Hudson N 130km 500cm diff inf and deg 90 mascond using 350km grid/";
      break;
    }
    case 136:{//produced by analysis_options.type == 1003 on 2010-09-07
      ifolder="output/simulations/Old area and old FES weighting code, negpos sums, Hudson N 130km 500cm diff inf and deg 90 mascond using 50km grid/";
      break;
    }
    case 137:{//produced by analysis_options.type == 1003 on 2010-09-07
      ifolder="output/simulations/New area and new FES weighting code, negpos sums, Hudson N 130km 500cm diff inf and deg 90 mascond using 350km grid/";
      break;
    }
    case 138:{//produced by analysis_options.type == 1003 on 2010-09-07
      ifolder="output/simulations/New area and new FES weighting code, negpos sums, Hudson N 130km 500cm diff inf and deg 90 mascond using 50km grid/";
      break;
    }
    case 139:{//produced by analysis_options.type == 1003 on 2010-09-07
      ifolder="output/simulations/Hudson N 130km 500cm diff inf and deg 90 mascond using 350km grid, old area and weighting minus new/";
      break;
    }
    case 140:{//produced by analysis_options.type == 1003 on 2010-09-07
      ifolder="output/simulations/Hudson N 130km 500cm diff inf and deg 90 mascond using 50km grid, old area and weighting minus new/";
      break;
    }
    case 141:{//produced by analysis_options.type == 1003 on 2010-09-07
      ifolder="output/simulations/Hudson N 130km 500cm orig mascond using 350km grid/";
      break;
    }
    case 142:{//produced by analysis_options.type == 1003 on 2010-09-07
      ifolder="output/simulations/Hudson N 130km 500cm orig mascond using 50km grid/";
      break;
    }
    case 143:{//produced by analysis_options.type == 1003 on 2010-09-10
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg20 mascond using 350km grid/";
      break;
    }
    case 144:{//produced by analysis_options.type == 1003 on 2010-09-10
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg20 mascond using 50km grid/";
      break;
    }
    case 145:{//produced by analysis_options.type == 1003 on 2010-09-10
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg40 mascond using 350km grid/";
      break;
    }
    case 146:{//produced by analysis_options.type == 1003 on 2010-09-10
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg40 mascond using 50km grid/";
      break;
    }
    case 147:{//produced by analysis_options.type == 1003 on 2010-09-10
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg60 mascond using 350km grid/";
      break;
    }
    case 148:{//produced by analysis_options.type == 1003 on 2010-09-10
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg60 mascond using 50km grid/";
      break;
    }
    case 149:{//produced by analysis_options.type == 1003 on 2010-09-11
      ifolder="BROKENoutput/simulations/Hudson N 130km 500cm diff inf deg50 mascond using 350km grid/";
      break;
    }
    case 150:{//produced by analysis_options.type == 1003 on 2010-09-11
      ifolder="BROKENoutput/simulations/Hudson N 130km 500cm diff inf deg50 mascond using 50km grid/";
      break;
    }
    case 151:{//produced by analysis_options.type == 1003 on 2010-09-11
      ifolder="BROKENoutput/simulations/Hudson N 130km 500cm diff inf deg75 mascond using 350km grid/";
      break;
    }
    case 152:{//produced by analysis_options.type == 1003 on 2010-09-11
      ifolder="BROKENoutput/simulations/Hudson N 130km 500cm diff inf deg75 mascond using 50km grid/";
      break;
    }
    case 153:{//produced by analysis_options.type == 1003 on 2010-09-11
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg90 mascond using 350km grid/";
      break;
    }
    case 154:{//produced by analysis_options.type == 1003 on 2010-09-11
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg90 mascond using 50km grid/";
      break;
    }
    case 155:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg55 mascond using 350km grid/";
      break;
    }
    case 156:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg55 mascond using 50km grid/";
      break;
    }
    case 157:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg65 mascond using 350km grid/";
      break;
    }
    case 158:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg65 mascond using 50km grid/";
      break;
    }
    case 159:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg70 mascond using 350km grid/";
      break;
    }
    case 160:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg70 mascond using 50km grid/";
      break;
    }
    case 161:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg80 mascond using 350km grid/";
      break;
    }
    case 162:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg80 mascond using 50km grid/";
      break;
    }
    case 163:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg85 mascond using 350km grid/";
      break;
    }
    case 164:{//produced by analysis_options.type == 1003 on 2010-09-13
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg85 mascond using 50km grid/";
      break;
    }
    case 165:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg25 mascond using 350km grid/";
      break;
    }
    case 166:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg25 mascond using 50km grid/";
      break;
    }
    case 167:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg30 mascond using 350km grid/";
      break;
    }
    case 168:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg30 mascond using 50km grid/";
      break;
    }
    case 169:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg49 mascond using 350km grid/";
      break;
    }
    case 170:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg49 mascond using 50km grid/";
      break;
    }
    case 171:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg51 mascond using 350km grid/";
      break;
    }
    case 172:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg51 mascond using 50km grid/";
      break;
    }
    case 173:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg74 mascond using 350km grid/";
      break;
    }
    case 174:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg74 mascond using 50km grid/";
      break;
    }
    case 175:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg76 mascond using 350km grid/";
      break;
    }
    case 176:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg76 mascond using 50km grid/";
      break;
    }
    case 177:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg50take2 mascond using 350km grid/";
      break;
    }
    case 178:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg50take2 mascond using 50km grid/";
      break;
    }
    case 179:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg75take2 mascond using 350km grid/";
      break;
    }
    case 180:{//produced by analysis_options.type == 1003 on 2010-09-14
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg75take2 mascond using 50km grid/";
      break;
    }
    case 181:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg10 mascond using 350km grid/";
      break;
    }
    case 182:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg10 mascond using 50km grid/";
      break;
    }
    case 183:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg27 mascond using 350km grid/";
      break;
    }
    case 184:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg27 mascond using 50km grid/";
      break;
    }
    case 185:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg32 mascond using 350km grid/";
      break;
    }
    case 186:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg32 mascond using 50km grid/";
      break;
    }
    case 187:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg35 mascond using 350km grid/";
      break;
    }
    case 188:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg35 mascond using 50km grid/";
      break;
    }
    case 189:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg37 mascond using 350km grid/";
      break;
    }
    case 190:{//produced by analysis_options.type == 1003 on 2010-09-15
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg37 mascond using 50km grid/";
      break;
    }
    case 191:{//produced by analysis_options.type == 1003 on 2010-09-20
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg110 mascond using 350km grid/";
      break;
    }
    case 192:{//produced by analysis_options.type == 1003 on 2010-09-20
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg110 mascond using 50km grid/";
      break;
    }
    case 193:{//produced by analysis_options.type == 1003 on 2010-09-20
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg130 mascond using 350km grid/";
      break;
    }
    case 194:{//produced by analysis_options.type == 1003 on 2010-09-20
      ifolder="output/simulations/Hudson N 130km 500cm diff inf deg130 mascond using 50km grid/";
      break;
    }
    case 195:{//produced by analysis_options.type == 1003 on 2010-09-22
      ifolder="output/simulations/FES M2,K1, diff inf and deg90, 350km, new areas/";
      break;
    }
    case 196:{//produced by analysis_options.type == 1003 on 2010-09-22
      ifolder="output/simulations/FES M2,K1, diff inf and deg90, 230km, new areas/";
      break;
    }
    case 197:{//produced by analysis_options.type == 1003 on 2010-09-22
      ifolder="output/simulations/FES M2,K1, diff inf and deg90, 150km, new areas/";
      break;
    }
    case 198:{//produced by analysis_options.type == 1003 on 2010-09-22
      ifolder="output/simulations/FES M2,K1, diff inf and deg90, 100km, new areas/";
      break;
    }
    case 199:{//produced by analysis_options.type == 1003 on 2010-09-22
      ifolder="output/simulations/FES M2,K1, diff inf and deg90, 50km, new areas/";
      break;
    }
    case 200:{//produced by analysis_options.type == 10056 on 2011-02-02
      ifolder="output/simulations/Type_10056_230km_gr_type_10/";
      break;
    }
    case 201:{//produced by analysis_options.type == 10048 on 2011-04-03
      ifolder="output/simulations/Type 10048, 100km type 10 gr/";
      break;
    }
    case 202:{//produced by analysis_options.type == 10048 on 2011-04-03
      ifolder="output/simulations/Type 10048, 1050km type 10 gr/";
      break;
    }
  }//End of switch-case-break.

  //Use ifolder set in switch-case above to record input folder.
  input_folder.append(ifolder.c_str());
  current_plot_options.inputfolder = ifolder;
  
  //Load options that were used to generate simulations.
  input_file = input_folder; input_file.append("options.txt");
  load_options(input_file, input, region.options, ancillary, grid, model.options, results, plot_options, insitu,1);

  results.options.output_choice = 1;
  
  //Over-ride certain options.
  input.options.filename = "input_and_orbit_land_and_ocean_edited.txt";
  //input.options.filename = "input_and_orbit_deg90_minus_deg150_2008_20s_smoothing.txt";
  //input.options.filename = "input_and_orbit_7yrs_noascending.txt";
  //input.options.filename = "input_and_orbit_7yrs_fixed_orbit.txt";
  //input.options.filename = "input_and_orbit_hudson_swaths.txt";
  //input.options.filename = "input_and_orbit_short2.txt";
  //input.options.filename = "input_and_orbit_75N_250k_pts.txt";
  //input.options.filename = "input_and_orbit_NP_cap_2000km_less_short.txt";
  plot_options.inputfolder = current_plot_options.inputfolder;
  input.options.output_filename=current_input_options.output_filename;
  input.options.output_folder="data/GRACE/";//same for all.
  
  //Should set the multipliers and support grid options here.
  grid.options.support_type=0;
  grid.options.support_lat_multiplier=3;
  grid.options.support_lon_multiplier=grid.options.support_lat_multiplier;

  cout<<"Loading output from folder "<<plot_options.inputfolder<<endl;

  //Load ancillary data (topography, temperatures, etc) from disk.
  load_ancillary(ancillary, 1);

  //load_(input_)output() expects a grid to already be defined.
  define_grid(grid, ancillary, results);
  //for(i=0;i<(long long)grid.wcover.size();i++) grid.wcover.at(i) = 1.0;
  
  //Supporting grid is required for some types of perform_upward_continuation
  define_support_grid(grid);

  region.options.type = 2;//Seems to be fast and compact enough for now.
  region.options.parallel = 1;//Needs to be 1 - don't have seq code working.
  region.options.analysis_list_cache_only = 0;//THESE SHOULD ALWAYS BE O!
  region.options.analysis_list_choice = 0;

  //If requested, define regions in which to upward convert separately.
  region = define_region(region.options, grid, 1);

  //Load/create binindices using current input options, not from load_output.
  load_input(input,grid,region);

  //Load whichever files were specified in plot_options.inputfolder in switch-case
  load_output(results,plot_options,grid);
  
  //2010-02-03 Addition: keeps simulated phases consistent with new input timeseries.
  results.options.current_phase_format = 1;//Assume that all files are in J2000 format.
  results.options.adjust_phases_choice = 4;//Make rel. to input.epoch.
  adjust_phases(input, results);
  
  //(THIS NEEDS TO BE DEFINED AFTER LOAD_OUTPUT- ANNOYING!)
  //Controls upward continuation method (pts vs disks, etc).
  //The newer analysis types solve y=Hx+e, where "H" is set up as in create_options in gaia.cpp.
  results.options.h_matrix_choice = 202;//101=1 here.
  results.options.nmax = 200;

  //Set to the value appropriate for the computer on which this program runs.
  results.options.numprocesses = 1;
  
  if((long long)region.lat.size() == 0) cout<<"HAVEN'T WRITTEN NON-REGION CODE!"<<endl;
  else{
    //Regions are not analyzed in a direct order- 0,1,2,3.  They are ordered
    //in different ways - region.options.analysis_list_choice controls most
    //of the variability.  For instance, regions with more in situ stations
    //can be analyzed first.
    build_analysis_region_list(grid, region);

    //Analyze regions either using sequential or parallel code:
    switch(region.options.parallel){
      case 0:{//Sequential region code.
        cout<<"HAVEN'T WRITTEN THIS YET!"<<endl;
        break;
      }
      case 1:{//Parallel region code.
        //Loop through regions, analyzing data in each region in a different
        //forked process, then writing the regional results to separate
        //files which will all be combined at the end.

        //Loop through regions, start a new process for each region.
        for(j=0;j<(long long)region.indices_to_analyze.size();j++){
          //Figure out which region index should be analyzed on this loop.    
          i=region.indices_to_analyze.at(j);
        
          switch(pid = fork()){
            case -1:{
              perror("fork");//Something went wrong!
              cout<<"Couldn't open fork!"<<endl;
              exit(1);//Parent exits.
              break;
            }
            case 0:{//This code is run in the child process that fork creates
              //This code is very similar to sequential region code.
              //So comments have been stripped- just look at sequential code
              //above to see what the commands are intended to do.
              results.options.region_index = i;
              
              //Now create the prefix that will prepend all mesgs in this reg.
              results.options.prefix = "Region ";
              sprintf(s,"%4lld",results.options.region_index+1);
              results.options.prefix.append(s);

              define_regional_grid(grid,region,regional_grid,i);
              
              //New function.
              copy_results_from_global_to_regional(regional_results,results,region,grid,regional_grid,i);
              
              if(region.all_grid_indices.at(i).size() > 0){
                region.input = load_regional_input((int)i,input,region);
              }
              else cout<<"Region "<<setw(4)<<i+1<<" of "<<(long long)region.indices_to_analyze.size()<<": skipping loading of input data."<<endl;
              
              if(region.all_grid_indices.at(i).size() > 0){
                cout<<"Region "<<setw(4)<<i+1<<" of "<<(long long)region.indices_to_analyze.size()<<": performing upward continuation."<<endl;
                //cout<<"scientific:"<<scientific<<setprecision(3)<<endl;
                perform_upward_continuation(region.input, regional_grid, regional_results);
                //perform_upward_continuation2(region.input, regional_grid, regional_results, regional_results,0);
                //cout<<"After upcont, accel["<<0<<"] = "<<scientific<<setprecision(3)<<region.input.accel.at(0)<<endl;
              }
              else cout<<"Skipping upward continuation in region "<<i+1<<" of "<<(long long)region.indices_to_analyze.size()<<endl;
              
              //base = region.input.options.output_filename;
              //region.input.options.output_filename = "input_and_orbit_sima_global_region.txt";
              //write_input(region.input);
              //region.input.options.output_filename = base;

              //Write results from this region's process to disk so that
              //the main program can compile all regional results together
              //once all the processes are done.
              base = "region"; sprintf(s,"_%05lld_input.txt",i+1);
              base.append(s);
              save_regional_input(base, region.input);
              
              exit(i);//Exit value of child process is the region index.
              break;
            }//End of child process commands.
            default:{//This code runs in the parent process.
              //If the number of region processes already started is 
              //greater to or equal to the numprocesses, wait until one
              //of the processes finishes before starting another.
              if(i+1 >= results.options.numprocesses) wait(&rv);
              break;
            }//End of parent process commands.
          }//End of switch-case-break for "parent or child".
        }//End of loop through regions.
        
        //Wait for still-running processes (should be "numprocesses" of em..)
        //But if there are fewer regions (being analyzed!) than numprocesses,
        //only wait for the number of regions that are really being analyzed.
        for(i=0;i<min((long long)results.options.numprocesses,(long long)region.indices_to_analyze.size());i++) wait(&rv);
        
        //Each of these processes has written its data to disk.  Search for
        //these files and load them sequentially, writing the input data to
        //a new file that is appended with each new file.  Delete each
        //region's input file after loading.
        combine_regional_inputs(input, region);
        
        break;
      }//End of case 1.
    }//End of parallel processing switch-case-break.
  }//End of region.type != 0 else statement.
  end_time = time(NULL);//Record time at end of program.
  timespan_conversion.seconds = (long long)(end_time - start_time);
  cout<<"Input generation via upward continuation took"<<sec2human(timespan_conversion)<<"."<<endl;

  return 0;
}
